﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Xml;
using System.Xml.Serialization;
using System.Collections.ObjectModel;
using System.IO;

namespace ManagerMachine
{
    [Serializable]
    [XmlRoot]
    public class CONFIG
    {      
        [XmlElement]
        public string IP_TABLE_SERVER{get;set;}
        [XmlElement]
        public int PORT_TABLE_SERVER { get; set; }
        [XmlElement]
        public string IP_LOGIN_SERVER { get; set; }
        [XmlElement]
        public int PORT_LOGIN_SERVER { get; set; }
        [XmlElement]
        public int MAX_USER_CONNECTION { get; set; }
        [XmlElement]
        public int MAX_TABLE { get; set; }
        [XmlElement]
        public RANGE_PORT_TABLE RANGE_PORT_TABLE { get; set; }
        [XmlElement]
        public string PATH_TABLE_SERVER_EXE { get; set; }
        [XmlElement]
        public string PATH_TABLE_SERVER_CONFIG { get; set; }
        //private ObservableCollection<MACHINE> machines = new ObservableCollection<MACHINE>();

        //[XmlArrayItem("MACHINE")]
        //public ObservableCollection<MACHINE> MACHINES
        //{
        //    get
        //    {
        //        if (machines != null)
        //            return machines;
        //        return null;
        //    }
        //    set
        //    {
        //        machines = value;
        //    }
        //}
        public static CONFIG Load(string path)
        {
            CONFIG obj = null;
            try
            {
                XmlSerializer xml = new XmlSerializer(typeof(CONFIG));
                StreamReader rd = new StreamReader(path);
                obj = xml.Deserialize(rd) as CONFIG;
                rd.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return obj;
        }
        
    }
    [Serializable]
    public class RANGE_PORT_TABLE
    {
        [XmlAttribute]
        public int MIN { get; set; }
        [XmlAttribute]
        public int MAX { get; set; }
    }
   
    
}
